"use strict";

exports.__esModule = true;
exports.valueSetter = valueSetter;
var _object = require("../../../helpers/object");
var _mixed = require("../../../helpers/mixed");
/**
 * Defines what value is set to an autocomplete-typed cell.
 *
 * @param {*} newValue The value to be set.
 * @param {number} row The visual row index.
 * @param {number} column The visual column index.
 * @returns {*} The new value to be set.
 */
function valueSetter(newValue, row, column) {
  const sourceDataAtCell = this.getSourceDataAtCell(this.toPhysicalRow(row), this.toPhysicalColumn(column));
  const isKeyValueObject = obj => (0, _object.isObject)(obj) && (0, _mixed.isDefined)(obj.key) && (0, _mixed.isDefined)(obj.value);
  if (isKeyValueObject(sourceDataAtCell)) {
    return isKeyValueObject(newValue) ? newValue : {
      key: newValue,
      value: newValue
    };
  }
  return newValue;
}